Q1: What is the trend in cases, mortality across geopgraphical regions?
Plot # of cases vs time
* For each geographical set:
* comparative longitudinal case trend (absolute & log scale)
* comparative longitudinal mortality trend
* death vs total correlation
| comparative_longitudinal_case_trend |
long |
time |
log_cases |
geography |
none (case type?) |
case_type |
[15, 50, 4] geography x (2 scale?) case type |
| comparative longitudinal case trend |
long |
time |
cases |
geography |
case_type |
? |
[15, 50, 4] geography x (2+ scale) case type |
| comparative longitudinal mortality trend |
wide |
time |
mortality rate |
geography |
none |
none |
[15, 50, 4] geography |
| death vs total correlation |
wide |
cases |
deaths |
geography |
none |
none |
[15, 50, 4] geography |
# total cases vs time
# death cases vs time
# mortality rate vs time
# death vs mortality
# death vs mortality
# total & death case vs time (same plot)
#<question> <x> <y> <colored> <facet> <dataset>
## trend in case/deaths over time, comapred across regions <time> <log cases> <geography*> <none> <.wide>
## trend in case/deaths over time, comapred across regions <time> <cases> <geography*> <case_type> <.long>
## trend in mortality rate over time, comapred across regions <time> <mortality rate> <geography*> <none>
## how are death/mortality related/correlated? <time> <log cases> <geography*> <none>
## how are death and case load correlated? <cases> <deaths>
# lm for each?? - > apply lm from each region starting from 100th case. m, b associated with each.
# input: geographical regsion, logcase vs day (100th case)
# output: m, b for each geographical region ID
#total/death on same plot- diffeer by 2 logs, so when plotting log, use pch. when plotting absolute, need to use free scales
#when plotting death and case on same, melt.
#CoronaCases - > filter sets (3)
#world - choose countries with sufficent data
N<-ddply(filter(Corona_Cases,Total_confirmed_cases>100),c("Country.Region"),summarise,n=length(Country.Region))
ggplot(filter(N,n<100),aes(x=n))+
geom_histogram()+
default_theme+
ggtitle("Distribution of number of days with at least 100 confirmed cases for each region")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

kable(arrange(N,-n),caption="Sorted number of days with at least 100 confirmed cases")
Sorted number of days with at least 100 confirmed cases
| US_state |
56315 |
| China |
142 |
| Diamond Princess |
123 |
| Korea, South |
113 |
| Japan |
112 |
| Italy |
110 |
| Iran |
107 |
| Singapore |
104 |
| France |
103 |
| Germany |
103 |
| Spain |
102 |
| US |
101 |
| Switzerland |
99 |
| United Kingdom |
99 |
| Belgium |
98 |
| Netherlands |
98 |
| Norway |
98 |
| Sweden |
98 |
| Austria |
96 |
| Malaysia |
95 |
| Australia |
94 |
| Bahrain |
94 |
| Denmark |
94 |
| Canada |
93 |
| Qatar |
93 |
| Iceland |
92 |
| Brazil |
91 |
| Czechia |
91 |
| Finland |
91 |
| Greece |
91 |
| Iraq |
91 |
| Israel |
91 |
| Portugal |
91 |
| Slovenia |
91 |
| Egypt |
90 |
| Estonia |
90 |
| India |
90 |
| Ireland |
90 |
| Kuwait |
90 |
| Philippines |
90 |
| Poland |
90 |
| Romania |
90 |
| Saudi Arabia |
90 |
| Indonesia |
89 |
| Lebanon |
89 |
| Pakistan |
89 |
| San Marino |
89 |
| Thailand |
89 |
| Chile |
88 |
| Luxembourg |
87 |
| Peru |
87 |
| Russia |
87 |
| Ecuador |
86 |
| Mexico |
86 |
| Slovakia |
86 |
| South Africa |
86 |
| United Arab Emirates |
86 |
| Armenia |
85 |
| Colombia |
85 |
| Croatia |
85 |
| Panama |
85 |
| Serbia |
85 |
| Taiwan* |
85 |
| Turkey |
85 |
| Argentina |
84 |
| Bulgaria |
84 |
| Latvia |
84 |
| Uruguay |
84 |
| Algeria |
83 |
| Costa Rica |
83 |
| Dominican Republic |
83 |
| Hungary |
83 |
| Andorra |
82 |
| Bosnia and Herzegovina |
82 |
| Jordan |
82 |
| Lithuania |
82 |
| Morocco |
82 |
| New Zealand |
82 |
| North Macedonia |
82 |
| Vietnam |
82 |
| Albania |
81 |
| Cyprus |
81 |
| Malta |
81 |
| Moldova |
81 |
| Brunei |
80 |
| Burkina Faso |
80 |
| Sri Lanka |
80 |
| Tunisia |
80 |
| Ukraine |
79 |
| Azerbaijan |
78 |
| Ghana |
78 |
| Kazakhstan |
78 |
| Oman |
78 |
| Senegal |
78 |
| Venezuela |
78 |
| Afghanistan |
77 |
| Cote d’Ivoire |
77 |
| Cuba |
76 |
| Mauritius |
76 |
| Uzbekistan |
76 |
| Cambodia |
75 |
| Cameroon |
75 |
| Honduras |
75 |
| Nigeria |
75 |
| West Bank and Gaza |
75 |
| Belarus |
74 |
| Georgia |
74 |
| Bolivia |
73 |
| Kosovo |
73 |
| Kyrgyzstan |
73 |
| Montenegro |
73 |
| Congo (Kinshasa) |
72 |
| Kenya |
71 |
| Niger |
70 |
| Guinea |
69 |
| Rwanda |
69 |
| Trinidad and Tobago |
69 |
| Paraguay |
68 |
| Bangladesh |
67 |
| Djibouti |
65 |
| El Salvador |
64 |
| Guatemala |
63 |
| Madagascar |
62 |
| Mali |
61 |
| Congo (Brazzaville) |
58 |
| Jamaica |
58 |
| Gabon |
56 |
| Somalia |
56 |
| Tanzania |
56 |
| Ethiopia |
55 |
| Burma |
54 |
| Sudan |
53 |
| Liberia |
52 |
| Maldives |
50 |
| Equatorial Guinea |
49 |
| Cabo Verde |
47 |
| Sierra Leone |
45 |
| Guinea-Bissau |
44 |
| Togo |
44 |
| Zambia |
43 |
| Eswatini |
42 |
| Chad |
41 |
| Tajikistan |
40 |
| Haiti |
38 |
| Sao Tome and Principe |
38 |
| Benin |
36 |
| Nepal |
36 |
| Uganda |
36 |
| Central African Republic |
35 |
| South Sudan |
35 |
| Guyana |
33 |
| Mozambique |
32 |
| Yemen |
28 |
| Mongolia |
27 |
| Mauritania |
24 |
| Nicaragua |
24 |
| Malawi |
18 |
| Syria |
18 |
| Zimbabwe |
16 |
| Bahamas |
15 |
| Libya |
15 |
| Comoros |
13 |
| Suriname |
5 |
| Angola |
2 |
# Pick top 15 countries with data
max_colors<-12
# find way to fix this- China has diff provences. Plot doesnt look right...
sufficient_data<-arrange(filter(N,!Country.Region %in% c("US_state", "Diamond Princess")),-n)[1:max_colors,]
kable(sufficient_data,caption = paste0("Top ",max_colors," countries with sufficient data"))
Top 12 countries with sufficient data
| China |
142 |
| Korea, South |
113 |
| Japan |
112 |
| Italy |
110 |
| Iran |
107 |
| Singapore |
104 |
| France |
103 |
| Germany |
103 |
| Spain |
102 |
| US |
101 |
| Switzerland |
99 |
| United Kingdom |
99 |
Corona_Cases.world<-filter(Corona_Cases,Country.Region %in% c(sufficient_data$Country.Region))
#us
# - by state
Corona_Cases.US<-filter(Corona_Cases,Country.Region=="US" & Total_confirmed_cases>0)
# summarize
#!City %in% c("Unassigned")
# - specific cities
#mortality_rate!=Inf & mortality_rate<=1
head(Corona_Cases)
## Country.Region Province.State City Date Date.numeric
## 1 Afghanistan <NA> <NA> 2020-06-05 18418
## 2 Afghanistan <NA> <NA> 2020-04-08 18360
## 3 Afghanistan <NA> <NA> 2020-04-12 18364
## 4 Afghanistan <NA> <NA> 2020-04-07 18359
## 5 Afghanistan <NA> <NA> 2020-06-04 18417
## 6 Afghanistan <NA> <NA> 2020-05-21 18403
## Total_confirmed_deaths Total_confirmed_cases mortality_rate
## 1 309 18969 0.01628974
## 2 14 444 0.03153153
## 3 18 607 0.02965404
## 4 14 423 0.03309693
## 5 300 18054 0.01661682
## 6 193 8676 0.02224527
## Total_confirmed_cases.log Total_confirmed_deaths.log case100_date
## 1 4.278044 2.489958 18348
## 2 2.647383 1.146128 18348
## 3 2.783189 1.255273 18348
## 4 2.626340 1.146128 18348
## 5 4.256573 2.477121 18348
## 6 3.938320 2.285557 18348
## Days_since_100 Lat Long Population Total_confirmed_cases.per100
## 1 70 NA NA NA NA
## 2 12 NA NA NA NA
## 3 16 NA NA NA NA
## 4 11 NA NA NA NA
## 5 69 NA NA NA NA
## 6 55 NA NA NA NA
## Total_confirmed_deaths.per100
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 NA
Corona_Cases[!is.na(Corona_Cases$Province.State) & Corona_Cases$Province.State=="Pennsylvania" & Corona_Cases$City=="Delaware","City"]<-"Delaware_PA"
Corona_Cases.UScity<-filter(Corona_Cases,Province.State %in% c("Pennsylvania","Maryland","New York","New Jersey") & City %in% c("Bucks","Baltimore City", "New York","Burlington","Cape May","Delaware_PA"))
measure_vars_long<-c("Total_confirmed_cases.log","Total_confirmed_cases","Total_confirmed_deaths","Total_confirmed_deaths.log")
melt_arg_list<-list(variable.name = "case_type",value.name = "cases",measure.vars = c("Total_confirmed_cases","Total_confirmed_deaths"))
melt_arg_list$data=NULL
melt_arg_list$data=select(Corona_Cases.world,-ends_with(match = "log"))
Corona_Cases.world.long<-do.call(melt,melt_arg_list)
melt_arg_list$data=select(Corona_Cases.UScity,-ends_with(match = "log"))
Corona_Cases.UScity.long<-do.call(melt,melt_arg_list)
melt_arg_list$data=select(Corona_Cases.US_state,-ends_with(match = "log"))
Corona_Cases.US_state.long<-do.call(melt,melt_arg_list)
Corona_Cases.world.long$cases.log<-log(Corona_Cases.world.long$cases,10)
Corona_Cases.US_state.long$cases.log<-log(Corona_Cases.US_state.long$cases,10)
Corona_Cases.UScity.long$cases.log<-log(Corona_Cases.UScity.long$cases,10)
# what is the current death and total case load for US? For world? For states?
#-absolute
#-log
# what is mortality rate (US, world)
#-absolute
#how is death and case correlated? (US, world)
#-absolute
#Corona_Cases.US<-filter(Corona_Cases,Country.Region=="US" & Total_confirmed_cases>0)
#Corona_Cases.US.case100<-filter(Corona_Cases.US, Days_since_100>=0)
# linear model parameters
#(model_fit<-lm(formula = Total_confirmed_cases.log~Days_since_100,data= Corona_Cases.US.case100 ))
#(slope<-model_fit$coefficients[2])
#(intercept<-model_fit$coefficients[1])
# Correlation coefficient
#cor(x = Corona_Cases.US.case100$Days_since_100,y = Corona_Cases.US.case100$Total_confirmed_cases.log)
##------------------------------------------
## Plot World Data
##------------------------------------------
# Timestamp for world
timestamp_plot.world<-paste("Most recent date for which data available:",max(Corona_Cases.world$Date))#timestamp(quiet = T,prefix = "Updated ",suffix = " (EST)")
# Base template for plots
baseplot.world<-ggplot(data=NULL,aes(x=Days_since_100,col=Country.Region))+
default_theme+
scale_color_brewer(type = "qualitative",palette = "Paired")+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))+
theme(legend.position = "bottom",plot.title = element_text(size=12))
##/////////////////////////
### Plot Longitudinal cases
(Corona_Cases.world.long.plot<-baseplot.world+
geom_point(data=Corona_Cases.world.long,aes(y=cases))+
geom_line(data=Corona_Cases.world.long,aes(y=cases))+
facet_wrap(~case_type,scales = "free_y",ncol=1)+
ggtitle(timestamp_plot.world)
)

(Corona_Cases.world.loglong.plot<-baseplot.world+
geom_point(data=Corona_Cases.world.long,aes(y=cases.log))+
geom_line(data=Corona_Cases.world.long,aes(y=cases.log))+
facet_wrap(~case_type,scales = "free_y",ncol=1)+
ggtitle(timestamp_plot.world))

##/////////////////////////
### Plot Longitudinal mortality rate
(Corona_Cases.world.mortality.plot<-baseplot.world+
geom_point(data=Corona_Cases.world,aes(y=mortality_rate))+
geom_line(data=Corona_Cases.world,aes(y=mortality_rate))+
ylim(c(0,0.3))+
ggtitle(timestamp_plot.world))
## Warning: Removed 100 rows containing missing values (geom_point).
## Warning: Removed 100 row(s) containing missing values (geom_path).

##/////////////////////////
### Plot death vs total case correlation
(Corona_Cases.world.casecor.plot<-ggplot(Corona_Cases.world,aes(x=Total_confirmed_cases,y=Total_confirmed_deaths,col=Country.Region))+
geom_point()+
geom_line()+
default_theme+
scale_color_brewer(type = "qualitative",palette = "Paired")+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))+
theme(legend.position = "bottom",plot.title = element_text(size=12))+
ggtitle(timestamp_plot.world))

### Write polots
write_plot(Corona_Cases.world.long.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.long.plot.png"
write_plot(Corona_Cases.world.loglong.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.loglong.plot.png"
write_plot(Corona_Cases.world.mortality.plot,wd = results_dir)
## Warning: Removed 100 rows containing missing values (geom_point).
## Warning: Removed 100 row(s) containing missing values (geom_path).
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.mortality.plot.png"
write_plot(Corona_Cases.world.casecor.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/Corona_Cases.world.casecor.plot.png"
##------------------------------------------
## Plot US State Data
##-----------------------------------------
baseplot.US<-ggplot(data=NULL,aes(x=Days_since_100_state,col=case_type))+
default_theme+
facet_wrap(~Province.State)+
ggtitle(paste("Log10 cases over time,",timestamp_plot.world))
Corona_Cases.US_state.long.plot<-baseplot.US+geom_point(data=Corona_Cases.US_state.long,aes(y=cases.log))
##------------------------------------------
## Plot US City Data
##-----------------------------------------
Corona_Cases.US.plotdata<-filter(Corona_Cases.US_state,Province.State %in% c("Pennsylvania","Maryland","New York","New Jersey") &
City %in% c("Bucks","Baltimore City", "New York","Burlington","Cape May","Delaware_PA") &
Total_confirmed_cases>0)
timestamp_plot<-paste("Most recent date for which data available:",max(Corona_Cases.US.plotdata$Date))#timestamp(quiet = T,prefix = "Updated ",suffix = " (EST)")
city_colors<-c("Bucks"='#beaed4',"Baltimore City"='#386cb0', "New York"='#7fc97f',"Burlington"='#fdc086',"Cape May"="#e78ac3","Delaware_PA"="#b15928")
##/////////////////////////
### Plot death vs total case correlation
(Corona_Cases.city.loglong.plot<-ggplot(melt(Corona_Cases.US.plotdata,measure.vars = c("Total_confirmed_cases.log","Total_confirmed_deaths.log"),variable.name = "case_type",value.name = "cases"),aes(x=Date,y=cases,col=City,pch=case_type))+
geom_point(size=4)+
geom_line()+
default_theme+
#facet_wrap(~case_type)+
ggtitle(paste("Log10 total and death cases over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.long.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(x=Date,y=Total_confirmed_cases,col=City))+
geom_point(size=4)+
geom_line()+
default_theme+
facet_grid(~Province.State,scales = "free_y")+
ggtitle(paste("MD, PA, NJ total cases over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))
+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.mortality.plot<-ggplot(Corona_Cases.US.plotdata,aes(x=Date,y=mortality_rate,col=City))+
geom_point(size=3)+
geom_line(size=2)+
default_theme+
ggtitle(paste("Mortality rate (deaths/total) over time,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors)+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

(Corona_Cases.city.casecor.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(y=Total_confirmed_deaths,x=Total_confirmed_cases,col=City))+
geom_point(size=3)+
geom_line(size=2)+
default_theme+
ggtitle(paste("Correlation of death vs total cases,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12))+
scale_color_manual(values = city_colors))

(Corona_Cases.city.long.normalized.plot<-ggplot(filter(Corona_Cases.US.plotdata,Province.State !="New York"),aes(x=Date,y=Total_confirmed_cases.per100,col=City))+
geom_point(size=4)+
geom_line()+
default_theme+
facet_grid(~Province.State)+
ggtitle(paste("MD, PA, NJ total cases over time per 100 people,",timestamp_plot))+
theme(legend.position = "bottom",plot.title = element_text(size=12),axis.text.x = element_text(angle=45,hjust=1))+
scale_color_manual(values = city_colors) +
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))

write_plot(Corona_Cases.city.long.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.long.plot.png"
write_plot(Corona_Cases.city.loglong.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.loglong.plot.png"
write_plot(Corona_Cases.city.mortality.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.mortality.plot.png"
write_plot(Corona_Cases.city.casecor.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.casecor.plot.png"
write_plot(Corona_Cases.city.long.normalized.plot,wd = results_dir_custom)
## [1] "/Users/stevensmith/Projects/coronavirus/results/custom/Corona_Cases.city.long.normalized.plot.png"
Q1b what is the model
Fit the cases to a linear model 1. Find time at which the case vs date becomes linear in each plot
2. Fit linear model for each city
# What is the predict # of cases for the next few days?
# How is the model performing historically?
Corona_Cases.US_state.summary<-ddply(Corona_Cases.US_state,
c("Province.State","Date"),
summarise,
Total_confirmed_cases_perstate=sum(Total_confirmed_cases)) %>%
filter(Total_confirmed_cases_perstate>100)
# Compute the states with the most cases (for coloring and for linear model)
top_states_totals<-head(ddply(Corona_Cases.US_state.summary,c("Province.State"),summarise, Total_confirmed_cases_perstate.max=max(Total_confirmed_cases_perstate)) %>% arrange(-Total_confirmed_cases_perstate.max),n=max_colors)
kable(top_states_totals,caption = "Top 12 States, total count ")
top_states<-top_states_totals$Province.State
# Manually fix states so that Maryland is switched out for New York
top_states_modified<-c(top_states[top_states !="New York"],"Maryland")
# Plot with all states:
(Corona_Cases.US_state.summary.plot<-ggplot(Corona_Cases.US_state.summary,aes(x=Date,y=Total_confirmed_cases_perstate))+
geom_point()+
geom_point(data=filter(Corona_Cases.US_state.summary,Province.State %in% top_states),aes(col=Province.State))+
scale_color_brewer(type = "qualitative",palette = "Paired")+
default_theme+
theme(axis.text.x = element_text(angle=45,hjust=1),legend.position = "bottom")+
ggtitle("Total confirmed cases per state, top 12 colored")+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))
##------------------------------------------
## Fit linear model to time vs total cases
##-----------------------------------------
# First, find the date at which each state's cases vs time becomes lienar (2nd derivative is about 0)
li<-ddply(Corona_Cases.US_state.summary,c("Province.State"),find_linear_index)
# Compute linear model for each state starting at the point at which data becomes linear
for(i in 1:nrow(li)){
Province.State.i<-li[i,"Province.State"]
date.i<-li[i,"V1"]
data.i<-filter(Corona_Cases.US_state.summary,Province.State==Province.State.i & as.numeric(Date) >= date.i)
model_results<-lm(data.i,formula = Total_confirmed_cases_perstate~Date)
slope<-model_results$coefficients[2]
intercept<-model_results$coefficients[1]
li[li$Province.State==Province.State.i,"m"]<-slope
li[li$Province.State==Province.State.i,"b"]<-intercept
}
# Compute top state case load with fitted model
(Corona_Cases.US_state.lm.plot<-ggplot(filter(Corona_Cases.US_state.summary,Province.State %in% top_states_modified ))+
geom_abline(data=filter(li,Province.State %in% top_states_modified),
aes(slope = m,intercept = b,col=Province.State),lty=2)+
geom_point(aes(x=Date,y=Total_confirmed_cases_perstate,col=Province.State))+
scale_color_brewer(type = "qualitative",palette = "Paired")+
default_theme+
theme(axis.text.x = element_text(angle=45,hjust=1),legend.position = "bottom")+
ggtitle("Total confirmed cases per state, top 12 colored")+
scale_x_date(date_breaks="1 week",date_minor_breaks="1 day"))
##------------------------------------------
## Predict the number of total cases over the next week
##-----------------------------------------
predicted_days<-c(0,1,2,3,7)+as.numeric(as.Date("2020-04-20"))
predicted_days_df<-data.frame(matrix(ncol=3))
names(predicted_days_df)<-c("Province.State","days","Total_confirmed_cases_perstate")
# USe model parameters to estiamte case loads
for(state.i in top_states_modified){
predicted_days_df<-rbind(predicted_days_df,
data.frame(Province.State=state.i,
prediction_model(m = li[li$Province.State==state.i,"m"],
b =li[li$Province.State==state.i,"b"] ,
days =predicted_days )))
}
predicted_days_df$Date<-as.Date(predicted_days_df$days,origin="1970-01-01")
kable(predicted_days_df,caption = "Predicted total cases over the next week for selected states")
##------------------------------------------
## Write plots
##-----------------------------------------
write_plot(Corona_Cases.US_state.summary.plot,wd = results_dir)
write_plot(Corona_Cases.US_state.lm.plot,wd = results_dir)
##------------------------------------------
## Write tables
##-----------------------------------------
write.csv(predicted_days_df,file = paste0(results_dir,"predicted_total_cases_days.csv"),quote = F,row.names = F)
Q2: What is the predicted number of cases?
What is the prediction of COVID-19 based on model thus far? Additional questions:
WHy did it take to day 40 to start a log linear trend? How long will it be till x number of cases? When will the plateu happen? Are any effects noticed with social distancing? Delays
##------------------------------------------
## Prediction and Prediction Accuracy
##------------------------------------------
today_num<-max(Corona_Cases.US$Days_since_100)
predicted_days<-today_num+c(1,2,3,7)
#mods = dlply(mydf, .(x3), lm, formula = y ~ x1 + x2)
#today:
Corona_Cases.US[Corona_Cases.US$Days_since_100==(today_num-1),]
Corona_Cases.US[Corona_Cases.US$Days_since_100==today_num,]
Corona_Cases.US$type<-"Historical"
#prediction_values<-prediction_model(m=slope,b=intercept,days = predicted_days)$Total_confirmed_cases
histoical_model<-data.frame(date=today_num,m=slope,b=intercept)
tmp<-data.frame(state=rep(c("A","B"),each=3),x=c(1,2,3,4,5,6))
tmp$y<-c(tmp[1:3,"x"]+5,tmp[4:6,"x"]*5+1)
ddply(tmp,c("state"))
lm(data =tmp,formula = y~x )
train_lm<-function(input_data,subset_coulmn,formula_input){
case_models <- dlply(input_data, subset_coulmn, lm, formula = formula_input)
case_models.parameters <- ldply(case_models, coef)
case_models.parameters<-rename(case_models.parameters,c("b"="(Intercept)","m"=subset_coulmn))
return(case_models.parameters)
}
train_lm(tmp,"state")
dlply(input_data, subset_coulmn, lm,m=)
# model for previous y days
#historical_model_predictions<-data.frame(day_x=NULL,Days_since_100=NULL,Total_confirmed_cases=NULL,Total_confirmed_cases.log=NULL)
# for(i in c(1,2,3,4,5,6,7,8,9,10)){
# #i<-1
# day_x<-today_num-i # 1, 2, 3, 4
# day_x_nextweek<-day_x+c(1,2,3)
# model_fit_x<-lm(data = filter(Corona_Cases.US.case100,Days_since_100 < day_x),formula = Total_confirmed_cases.log~Days_since_100)
# prediction_day_x_nextweek<-prediction_model(m = model_fit_x$coefficients[2],b = model_fit_x$coefficients[1],days = day_x_nextweek)
# prediction_day_x_nextweek$type<-"Predicted"
# acutal_day_x_nextweek<-filter(Corona_Cases.US,Days_since_100 %in% day_x_nextweek) %>% select(c(Days_since_100,Total_confirmed_cases,Total_confirmed_cases.log))
# acutal_day_x_nextweek$type<-"Historical"
# historical_model_predictions.i<-data.frame(day_x=day_x,rbind(acutal_day_x_nextweek,prediction_day_x_nextweek))
# historical_model_predictions<-rbind(historical_model_predictions.i,historical_model_predictions)
# }
#historical_model_predictions.withHx<-rbind.fill(historical_model_predictions,data.frame(Corona_Cases.US,type="Historical"))
#historical_model_predictions.withHx$Total_confirmed_cases.log2<-log(historical_model_predictions.withHx$Total_confirmed_cases,2)
(historical_model_predictions.plot<-ggplot(historical_model_predictions.withHx,aes(x=Days_since_100,y=Total_confirmed_cases.log,col=type))+
geom_point(size=3)+
default_theme+
theme(legend.position = "bottom")+
#geom_abline(slope = slope,intercept =intercept,lty=2)+
#facet_wrap(~case_type,ncol=1)+
scale_color_manual(values = c("Historical"="#377eb8","Predicted"="#e41a1c")))
write_plot(historical_model_predictions.plot,wd=results_dir)
Q3: What is the effect on social distancing, descreased mobility on case load?
Load data from Google which compoutes % change in user mobility relative to baseline for * Recreation
* Workplace
* Residence
* Park
* Grocery
Data from https://www.google.com/covid19/mobility/
# See pre-processing section for script on gathering mobility data
# UNDER DEVELOPMENT
mobility<-read.csv("/Users/stevensmith/Projects/MIT_COVID19/mobility.csv",header = T,stringsAsFactors = F)
#mobility$Retail_Recreation<-as.numeric(sub(mobility$Retail_Recreation,pattern = "%",replacement = ""))
#mobility$Workplace<-as.numeric(sub(mobility$Workplace,pattern = "%",replacement = ""))
#mobility$Residential<-as.numeric(sub(mobility$Residential,pattern = "%",replacement = ""))
##------------------------------------------
## Show relationship between mobility and caseload
##------------------------------------------
mobility$County<-gsub(mobility$County,pattern = " County",replacement = "")
Corona_Cases.US_state.mobility<-merge(Corona_Cases.US_state,plyr::rename(mobility,c("State"="Province.State","County"="City")))
#Corona_Cases.US_state.tmp<-merge(metadata,Corona_Cases.US_state.tmp)
# Needs to happen upsteam, see todos
#Corona_Cases.US_state.tmp$Total_confirmed_cases.perperson<-Corona_Cases.US_state.tmp$Total_confirmed_cases/as.numeric(Corona_Cases.US_state.tmp$Population)
mobility_measures<-c("Retail_Recreation","Grocery_Pharmacy","Parks","Transit","Workplace","Residential")
plot_data<-filter(Corona_Cases.US_state.mobility, Date.numeric==max(Corona_Cases.US_state$Date.numeric) ) %>% melt(measure.vars=mobility_measures)
plot_data$value<-as.numeric(gsub(plot_data$value,pattern = "%",replacement = ""))
plot_data<-filter(plot_data,!is.na(value))
(mobility.plot<-ggplot(filter(plot_data,Province.State %in% c("Pennsylvania","Maryland","New Jersey","California","Delaware","Connecticut")),aes(y=Total_confirmed_cases.per100,x=value))+geom_point()+
facet_grid(Province.State~variable,scales = "free")+
xlab("Mobility change from baseline (%)")+
ylab(paste0("Confirmed cases per 100 people(Today)"))+
default_theme+
ggtitle("Mobility change vs cases"))

(mobility.global.plot<-ggplot(plot_data,aes(y=Total_confirmed_cases.per100,x=value))+geom_point()+
facet_wrap(~variable,scales = "free")+
xlab("Mobility change from baseline (%)")+
ylab(paste0("Confirmed cases (Today) per 100 people"))+
default_theme+
ggtitle("Mobility change vs cases"))

plot_data.permobility_summary<-ddply(plot_data,c("Province.State","variable"),summarise,cor=cor(y =Total_confirmed_cases.per100,x=value),median_change=median(x=value)) %>% arrange(-abs(cor))
kable(plot_data.permobility_summary,caption = "Ranked per-state mobility correlation with total confirmed cases")
Ranked per-state mobility correlation with total confirmed cases
| Alaska |
Transit |
1.0000000 |
-63.0 |
| Delaware |
Retail_Recreation |
1.0000000 |
-39.5 |
| Delaware |
Grocery_Pharmacy |
1.0000000 |
-17.5 |
| Delaware |
Parks |
-1.0000000 |
20.5 |
| Delaware |
Transit |
1.0000000 |
-37.0 |
| Delaware |
Workplace |
1.0000000 |
-37.0 |
| Delaware |
Residential |
-1.0000000 |
14.0 |
| Hawaii |
Grocery_Pharmacy |
0.9999788 |
-34.0 |
| Hawaii |
Retail_Recreation |
0.9922959 |
-56.0 |
| New Hampshire |
Parks |
0.9530303 |
-20.0 |
| Vermont |
Parks |
0.9336770 |
-35.5 |
| Maine |
Transit |
-0.9153180 |
-50.0 |
| Utah |
Residential |
-0.8888658 |
12.0 |
| Connecticut |
Grocery_Pharmacy |
-0.8861382 |
-6.0 |
| Hawaii |
Parks |
0.8363104 |
-72.0 |
| Utah |
Transit |
-0.8291928 |
-18.0 |
| South Dakota |
Parks |
0.8212771 |
-26.0 |
| Hawaii |
Transit |
0.7884139 |
-89.0 |
| Wyoming |
Parks |
-0.7849623 |
-4.0 |
| Alaska |
Workplace |
-0.7783669 |
-33.0 |
| Arizona |
Grocery_Pharmacy |
-0.7751668 |
-15.0 |
| Rhode Island |
Workplace |
-0.7648509 |
-39.5 |
| Massachusetts |
Workplace |
-0.7523893 |
-39.0 |
| Connecticut |
Transit |
-0.7477857 |
-50.0 |
| Vermont |
Grocery_Pharmacy |
-0.6576427 |
-25.0 |
| New York |
Workplace |
-0.6515408 |
-34.5 |
| Utah |
Parks |
-0.6344390 |
17.0 |
| Arizona |
Residential |
0.6324102 |
13.0 |
| Rhode Island |
Retail_Recreation |
-0.6264114 |
-45.0 |
| Alaska |
Grocery_Pharmacy |
-0.6220264 |
-7.0 |
| Alaska |
Residential |
0.6191911 |
13.0 |
| North Dakota |
Parks |
0.6172542 |
-34.0 |
| Hawaii |
Residential |
-0.6151452 |
19.0 |
| New Jersey |
Parks |
-0.6035832 |
-6.0 |
| Rhode Island |
Residential |
-0.6030669 |
18.5 |
| Nevada |
Transit |
-0.5989959 |
-20.0 |
| Maine |
Workplace |
-0.5974248 |
-30.0 |
| New York |
Retail_Recreation |
-0.5890553 |
-46.0 |
| Utah |
Workplace |
-0.5832217 |
-37.0 |
| Nebraska |
Workplace |
0.5828620 |
-32.0 |
| Arizona |
Retail_Recreation |
-0.5721797 |
-42.5 |
| New Jersey |
Workplace |
-0.5429925 |
-44.0 |
| Wyoming |
Transit |
-0.5376244 |
-17.0 |
| Idaho |
Residential |
-0.5363728 |
11.0 |
| New York |
Parks |
0.5295690 |
20.0 |
| Connecticut |
Retail_Recreation |
-0.5138229 |
-45.0 |
| Connecticut |
Residential |
0.5112331 |
14.0 |
| Kansas |
Parks |
0.4986140 |
72.0 |
| Massachusetts |
Retail_Recreation |
-0.4972982 |
-44.0 |
| Maine |
Parks |
0.4894549 |
-31.0 |
| New Jersey |
Grocery_Pharmacy |
-0.4834600 |
2.5 |
| New Mexico |
Grocery_Pharmacy |
-0.4810636 |
-11.0 |
| Montana |
Parks |
-0.4796329 |
-58.0 |
| Connecticut |
Workplace |
-0.4742959 |
-39.0 |
| Montana |
Residential |
0.4717634 |
14.0 |
| Iowa |
Parks |
-0.4717463 |
28.5 |
| West Virginia |
Parks |
0.4701947 |
-33.0 |
| Nebraska |
Residential |
-0.4666259 |
14.0 |
| Rhode Island |
Parks |
0.4526207 |
52.0 |
| New Mexico |
Residential |
0.4512141 |
13.5 |
| Maryland |
Workplace |
-0.4491352 |
-35.0 |
| North Dakota |
Retail_Recreation |
-0.4471316 |
-42.0 |
| New Jersey |
Retail_Recreation |
-0.4368898 |
-62.5 |
| Illinois |
Transit |
-0.4310289 |
-31.0 |
| Arizona |
Transit |
0.4308371 |
-38.0 |
| Pennsylvania |
Workplace |
-0.4237247 |
-36.0 |
| South Carolina |
Workplace |
0.4157476 |
-30.0 |
| New Mexico |
Parks |
0.4146560 |
-31.5 |
| Maryland |
Grocery_Pharmacy |
-0.4091531 |
-10.0 |
| Massachusetts |
Grocery_Pharmacy |
-0.4091048 |
-7.0 |
| New Jersey |
Transit |
-0.4075140 |
-50.5 |
| New Hampshire |
Residential |
-0.4017444 |
14.0 |
| Vermont |
Residential |
0.3940837 |
11.5 |
| Michigan |
Parks |
0.3893993 |
28.5 |
| Pennsylvania |
Retail_Recreation |
-0.3865474 |
-45.0 |
| Alabama |
Grocery_Pharmacy |
-0.3845963 |
-2.0 |
| Arkansas |
Parks |
0.3827358 |
-12.0 |
| Alabama |
Workplace |
-0.3811043 |
-29.0 |
| Oregon |
Workplace |
-0.3776803 |
-31.0 |
| Kentucky |
Parks |
-0.3750956 |
28.5 |
| Wyoming |
Workplace |
-0.3747455 |
-31.0 |
| New York |
Transit |
-0.3688685 |
-48.0 |
| New Mexico |
Retail_Recreation |
-0.3520013 |
-42.5 |
| Idaho |
Grocery_Pharmacy |
-0.3486839 |
-5.5 |
| Wisconsin |
Transit |
-0.3481425 |
-23.5 |
| Idaho |
Workplace |
-0.3466799 |
-29.0 |
| Oregon |
Parks |
-0.3462938 |
16.5 |
| Nebraska |
Grocery_Pharmacy |
0.3415999 |
-0.5 |
| California |
Transit |
-0.3307846 |
-42.0 |
| Wyoming |
Grocery_Pharmacy |
-0.3242293 |
-10.0 |
| Hawaii |
Workplace |
0.3231885 |
-46.0 |
| Maryland |
Retail_Recreation |
-0.3222845 |
-39.0 |
| Arkansas |
Retail_Recreation |
-0.3216719 |
-30.0 |
| North Dakota |
Workplace |
0.3162939 |
-40.0 |
| Virginia |
Transit |
-0.3157728 |
-33.0 |
| California |
Residential |
0.3153552 |
14.0 |
| Idaho |
Transit |
-0.3101230 |
-30.0 |
| Maine |
Retail_Recreation |
-0.3027213 |
-42.0 |
| California |
Parks |
-0.2997769 |
-38.5 |
| Minnesota |
Transit |
-0.2942195 |
-28.5 |
| Illinois |
Workplace |
-0.2895620 |
-30.5 |
| Colorado |
Residential |
0.2861959 |
14.0 |
| Florida |
Residential |
0.2853415 |
14.0 |
| Pennsylvania |
Parks |
0.2823193 |
12.0 |
| Missouri |
Residential |
-0.2816092 |
13.0 |
| Montana |
Transit |
0.2810459 |
-41.0 |
| Mississippi |
Residential |
0.2810255 |
13.0 |
| Nevada |
Residential |
0.2805279 |
17.0 |
| North Carolina |
Grocery_Pharmacy |
0.2803763 |
0.0 |
| Vermont |
Retail_Recreation |
0.2802302 |
-57.0 |
| North Carolina |
Workplace |
0.2695368 |
-31.0 |
| Georgia |
Grocery_Pharmacy |
-0.2658482 |
-10.0 |
| South Carolina |
Parks |
-0.2652238 |
-23.0 |
| Alabama |
Transit |
-0.2648984 |
-36.5 |
| Rhode Island |
Grocery_Pharmacy |
0.2634588 |
-7.5 |
| Texas |
Workplace |
0.2593114 |
-32.0 |
| Vermont |
Workplace |
-0.2588909 |
-43.0 |
| Maryland |
Residential |
0.2582406 |
15.0 |
| Pennsylvania |
Grocery_Pharmacy |
-0.2575567 |
-6.0 |
| Kansas |
Workplace |
0.2569225 |
-32.5 |
| Texas |
Residential |
-0.2543552 |
15.0 |
| Rhode Island |
Transit |
-0.2528446 |
-56.0 |
| Illinois |
Parks |
0.2512331 |
26.5 |
| Tennessee |
Workplace |
-0.2492550 |
-31.0 |
| Florida |
Parks |
-0.2432877 |
-43.0 |
| Alaska |
Retail_Recreation |
0.2395662 |
-39.0 |
| Tennessee |
Residential |
0.2364085 |
11.5 |
| New York |
Grocery_Pharmacy |
-0.2301335 |
8.0 |
| West Virginia |
Grocery_Pharmacy |
-0.2251599 |
-6.0 |
| Washington |
Grocery_Pharmacy |
0.2243587 |
-7.0 |
| Wisconsin |
Parks |
0.2232476 |
51.5 |
| Georgia |
Workplace |
-0.2231884 |
-33.5 |
| Nevada |
Retail_Recreation |
-0.2206094 |
-43.0 |
| South Dakota |
Workplace |
0.2132724 |
-35.0 |
| North Dakota |
Grocery_Pharmacy |
-0.2114182 |
-8.0 |
| Minnesota |
Parks |
0.2087876 |
-9.0 |
| Georgia |
Retail_Recreation |
-0.2071400 |
-41.0 |
| Montana |
Workplace |
-0.2062976 |
-40.0 |
| Idaho |
Retail_Recreation |
-0.1994250 |
-39.5 |
| West Virginia |
Workplace |
0.1991519 |
-33.0 |
| North Carolina |
Transit |
0.1985732 |
-32.0 |
| Utah |
Retail_Recreation |
-0.1961675 |
-40.0 |
| Mississippi |
Grocery_Pharmacy |
-0.1952519 |
-8.0 |
| Kansas |
Grocery_Pharmacy |
-0.1951776 |
-14.0 |
| Illinois |
Residential |
0.1941120 |
14.0 |
| Oregon |
Transit |
0.1937067 |
-27.5 |
| Arizona |
Parks |
-0.1908245 |
-44.5 |
| Colorado |
Parks |
-0.1903452 |
2.0 |
| North Carolina |
Residential |
0.1889768 |
13.0 |
| Arkansas |
Residential |
0.1882963 |
12.0 |
| Virginia |
Residential |
0.1859312 |
14.0 |
| Texas |
Parks |
0.1821099 |
-42.0 |
| Connecticut |
Parks |
0.1815763 |
43.0 |
| Wisconsin |
Residential |
-0.1776527 |
14.0 |
| Nebraska |
Transit |
-0.1735733 |
-9.0 |
| Missouri |
Workplace |
0.1730787 |
-28.0 |
| Kentucky |
Transit |
-0.1713968 |
-31.0 |
| Kentucky |
Grocery_Pharmacy |
0.1706162 |
4.0 |
| Indiana |
Parks |
-0.1700524 |
29.0 |
| Pennsylvania |
Transit |
-0.1692302 |
-42.0 |
| Oregon |
Residential |
0.1659095 |
10.5 |
| Nevada |
Workplace |
-0.1642381 |
-40.0 |
| New Hampshire |
Retail_Recreation |
-0.1628477 |
-41.0 |
| New Jersey |
Residential |
0.1628383 |
18.0 |
| Indiana |
Residential |
0.1623577 |
12.0 |
| Massachusetts |
Parks |
0.1618841 |
39.0 |
| New Mexico |
Transit |
0.1606930 |
-38.5 |
| Ohio |
Transit |
0.1565773 |
-28.0 |
| Iowa |
Transit |
0.1524402 |
-24.0 |
| South Dakota |
Residential |
0.1485329 |
15.0 |
| Michigan |
Workplace |
-0.1478876 |
-40.0 |
| Indiana |
Retail_Recreation |
0.1445007 |
-38.0 |
| Virginia |
Grocery_Pharmacy |
-0.1418520 |
-8.0 |
| California |
Grocery_Pharmacy |
-0.1397192 |
-11.5 |
| Alabama |
Parks |
0.1390553 |
-1.0 |
| Mississippi |
Retail_Recreation |
-0.1327979 |
-40.0 |
| Minnesota |
Retail_Recreation |
0.1302458 |
-40.0 |
| Tennessee |
Parks |
-0.1288353 |
10.5 |
| Wisconsin |
Workplace |
-0.1285068 |
-31.0 |
| North Dakota |
Residential |
-0.1269050 |
17.0 |
| North Dakota |
Transit |
0.1254749 |
-48.0 |
| Florida |
Retail_Recreation |
0.1250284 |
-43.0 |
| California |
Retail_Recreation |
-0.1245487 |
-44.0 |
| Missouri |
Transit |
-0.1228531 |
-24.5 |
| Texas |
Grocery_Pharmacy |
0.1221446 |
-14.0 |
| Mississippi |
Transit |
-0.1180793 |
-38.5 |
| Wyoming |
Residential |
0.1180478 |
12.5 |
| Wisconsin |
Grocery_Pharmacy |
0.1174008 |
-1.0 |
| Missouri |
Parks |
0.1137470 |
0.0 |
| Georgia |
Residential |
-0.1114710 |
13.0 |
| Kentucky |
Residential |
0.1110315 |
12.0 |
| North Carolina |
Retail_Recreation |
0.1093711 |
-34.0 |
| Nebraska |
Retail_Recreation |
0.1077230 |
-36.0 |
| South Dakota |
Transit |
-0.1073351 |
-40.0 |
| Nevada |
Parks |
0.1059216 |
-12.5 |
| Massachusetts |
Transit |
-0.1056549 |
-45.0 |
| Virginia |
Parks |
0.1055830 |
6.0 |
| Idaho |
Parks |
0.1047149 |
-22.0 |
| Arkansas |
Workplace |
-0.1046286 |
-26.0 |
| New Hampshire |
Grocery_Pharmacy |
-0.1025858 |
-6.0 |
| Oregon |
Grocery_Pharmacy |
0.1021927 |
-7.0 |
| Massachusetts |
Residential |
0.1017675 |
15.0 |
| Kansas |
Transit |
-0.1016290 |
-26.5 |
| Oklahoma |
Grocery_Pharmacy |
-0.1000828 |
-0.5 |
| Michigan |
Retail_Recreation |
-0.0999028 |
-53.0 |
| Maryland |
Transit |
-0.0992443 |
-39.0 |
| Alabama |
Retail_Recreation |
0.0984950 |
-39.0 |
| Michigan |
Transit |
0.0966554 |
-46.0 |
| Ohio |
Residential |
0.0959556 |
14.0 |
| Iowa |
Workplace |
0.0952537 |
-30.0 |
| Oklahoma |
Parks |
0.0944498 |
-18.5 |
| Washington |
Workplace |
-0.0935464 |
-38.0 |
| Michigan |
Residential |
0.0935114 |
15.0 |
| Texas |
Transit |
0.0924182 |
-41.0 |
| New York |
Residential |
0.0912760 |
17.5 |
| Indiana |
Workplace |
0.0882015 |
-34.0 |
| Mississippi |
Parks |
-0.0876805 |
-25.0 |
| Oklahoma |
Workplace |
0.0870034 |
-31.0 |
| Ohio |
Parks |
-0.0869618 |
67.5 |
| Virginia |
Workplace |
-0.0867909 |
-31.5 |
| Georgia |
Parks |
0.0845830 |
-6.0 |
| Utah |
Grocery_Pharmacy |
0.0844606 |
-4.0 |
| North Carolina |
Parks |
-0.0807240 |
7.0 |
| Minnesota |
Workplace |
-0.0802130 |
-33.0 |
| Oregon |
Retail_Recreation |
-0.0798551 |
-40.5 |
| Iowa |
Grocery_Pharmacy |
-0.0791425 |
4.0 |
| Pennsylvania |
Residential |
0.0783106 |
15.0 |
| Minnesota |
Residential |
-0.0763405 |
17.0 |
| Virginia |
Retail_Recreation |
-0.0752809 |
-35.0 |
| Washington |
Residential |
0.0747169 |
13.0 |
| Minnesota |
Grocery_Pharmacy |
0.0740046 |
-6.0 |
| Ohio |
Grocery_Pharmacy |
0.0733723 |
0.0 |
| Kentucky |
Retail_Recreation |
0.0723322 |
-29.0 |
| Maine |
Residential |
-0.0683959 |
11.0 |
| Florida |
Grocery_Pharmacy |
0.0670691 |
-14.0 |
| California |
Workplace |
-0.0660173 |
-36.0 |
| Alabama |
Residential |
-0.0650277 |
11.0 |
| Colorado |
Transit |
0.0647247 |
-36.0 |
| West Virginia |
Transit |
-0.0630719 |
-45.0 |
| Texas |
Retail_Recreation |
0.0600219 |
-40.0 |
| Washington |
Transit |
-0.0561229 |
-33.5 |
| West Virginia |
Residential |
-0.0547248 |
11.0 |
| Vermont |
Transit |
-0.0540271 |
-63.0 |
| South Carolina |
Transit |
0.0517456 |
-45.0 |
| Washington |
Parks |
0.0514921 |
-3.5 |
| Ohio |
Retail_Recreation |
0.0513874 |
-36.0 |
| Indiana |
Grocery_Pharmacy |
-0.0512868 |
-5.5 |
| New Hampshire |
Workplace |
0.0480237 |
-37.0 |
| Kentucky |
Workplace |
-0.0456446 |
-36.5 |
| Oklahoma |
Residential |
0.0448371 |
15.0 |
| Indiana |
Transit |
0.0423123 |
-29.0 |
| Illinois |
Grocery_Pharmacy |
-0.0408169 |
2.0 |
| Mississippi |
Workplace |
-0.0402548 |
-33.0 |
| Ohio |
Workplace |
-0.0361783 |
-35.0 |
| South Carolina |
Grocery_Pharmacy |
0.0345764 |
1.0 |
| South Dakota |
Retail_Recreation |
-0.0328386 |
-39.0 |
| Wisconsin |
Retail_Recreation |
0.0310009 |
-44.0 |
| Maine |
Grocery_Pharmacy |
-0.0306653 |
-13.0 |
| Wyoming |
Retail_Recreation |
-0.0287217 |
-39.0 |
| Georgia |
Transit |
-0.0285867 |
-35.0 |
| Colorado |
Grocery_Pharmacy |
-0.0281447 |
-17.0 |
| Michigan |
Grocery_Pharmacy |
-0.0280182 |
-11.0 |
| Iowa |
Retail_Recreation |
0.0274725 |
-38.0 |
| New Mexico |
Workplace |
0.0271814 |
-34.0 |
| Florida |
Transit |
-0.0270896 |
-49.0 |
| Missouri |
Retail_Recreation |
-0.0261404 |
-36.5 |
| South Carolina |
Residential |
-0.0259587 |
12.0 |
| Illinois |
Retail_Recreation |
0.0243136 |
-40.0 |
| Montana |
Grocery_Pharmacy |
-0.0229603 |
-16.0 |
| West Virginia |
Retail_Recreation |
-0.0229557 |
-38.5 |
| Arkansas |
Transit |
0.0216486 |
-27.0 |
| Tennessee |
Grocery_Pharmacy |
0.0212917 |
6.0 |
| Arizona |
Workplace |
-0.0203444 |
-35.0 |
| Iowa |
Residential |
-0.0202131 |
13.0 |
| Kansas |
Residential |
-0.0195269 |
13.0 |
| Florida |
Workplace |
-0.0194170 |
-33.0 |
| Colorado |
Retail_Recreation |
-0.0193849 |
-44.0 |
| Colorado |
Workplace |
0.0186891 |
-39.0 |
| Arkansas |
Grocery_Pharmacy |
-0.0175011 |
3.0 |
| Tennessee |
Transit |
0.0169037 |
-32.0 |
| Washington |
Retail_Recreation |
0.0163743 |
-42.0 |
| Oklahoma |
Transit |
0.0158671 |
-26.0 |
| Montana |
Retail_Recreation |
0.0154367 |
-51.0 |
| Maryland |
Parks |
0.0130171 |
27.0 |
| Tennessee |
Retail_Recreation |
-0.0121802 |
-30.0 |
| Oklahoma |
Retail_Recreation |
0.0104534 |
-31.0 |
| Nebraska |
Parks |
0.0103334 |
55.5 |
| Nevada |
Grocery_Pharmacy |
0.0092523 |
-12.5 |
| Kansas |
Retail_Recreation |
-0.0080117 |
-38.0 |
| New Hampshire |
Transit |
0.0057686 |
-57.0 |
| South Dakota |
Grocery_Pharmacy |
-0.0045838 |
-9.0 |
| Missouri |
Grocery_Pharmacy |
0.0021279 |
2.0 |
| South Carolina |
Retail_Recreation |
0.0008872 |
-35.0 |
| Alaska |
Parks |
NA |
29.0 |
| District of Columbia |
Retail_Recreation |
NA |
-69.0 |
| District of Columbia |
Grocery_Pharmacy |
NA |
-28.0 |
| District of Columbia |
Parks |
NA |
-65.0 |
| District of Columbia |
Transit |
NA |
-69.0 |
| District of Columbia |
Workplace |
NA |
-48.0 |
| District of Columbia |
Residential |
NA |
17.0 |
# sanity check
ggplot(filter(plot_data,Province.State %in% c("Pennsylvania","Maryland","New Jersey","California","Delaware","Connecticut")),aes(x=Total_confirmed_cases.per100,fill=variable))+geom_histogram()+
facet_grid(~Province.State)+
default_theme+
theme(legend.position = "bottom")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

write_plot(mobility.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/mobility.plot.png"
write_plot(mobility.global.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/mobility.global.plot.png"
(plot_data.permobility_summary.plot<-ggplot(plot_data.permobility_summary,aes(x=variable,y=median_change))+
geom_jitter(size=2,width=.2)+
#geom_jitter(data=plot_data.permobility_summary %>% arrange(-abs(median_change)) %>% head(n=15),aes(col=Province.State),size=2,width=.2)+
default_theme+
ggtitle("Per-Sate Median Change in Mobility")+
xlab("Mobility Meaure")+
ylab("Median Change from Baseline"))

write_plot(plot_data.permobility_summary.plot,wd = results_dir)
## [1] "/Users/stevensmith/Projects/coronavirus/results/plot_data.permobility_summary.plot.png"